import axios from 'axios';
import { getCookie } from '@/libs/cookies';
import {
	getStore,
	setStore
} from './storage';
let util = {};
util.millsToTime = function (mills) {
	if (!mills) {
		return "";
	}
	let s = mills / 1000;
	if (s < 60) {
		return s.toFixed(0) + " 秒"
	}
	let m = s / 60;
	if (m < 60) {
		return m.toFixed(0) + " 分钟"
	}
	let h = m / 60;
	if (h < 24) {
		return h.toFixed(0) + " 小时"
	}
	let d = h / 24;
	if (d < 30) {
		return d.toFixed(0) + " 天"
	}
	let month = d / 30
	if (month < 12) {
		return month.toFixed(0) + " 个月"
	}
	let year = month / 12
	return year.toFixed(0) + " 年"

};

util.inOf = function (arr, targetArr) {
	let res = true;
	arr.forEach(item => {
		if (targetArr.indexOf(item) < 0) {
			res = false;
		}
	});
	return res;
};

util.oneOf = function (ele, targetArr) {
	if (targetArr.indexOf(ele) >= 0) {
		return true;
	} else {
		return false;
	}
};

//登出
util.logout = function (vm, isJump = true, jumpPath = "/") {
	vm.$store.commit("logout", vm);
	window.location.href = "/";
	// if (jumpPath) {
	//   vm.$router.push({
	// 	path: jumpPath
	//   });
	// }
};
// 取分隔符前面的内容，舍弃分隔符后面内容
util.getBefore = function (data, split) {
	let sp = split || '.'
	if (!data) return
	let str = ''
	if (data.indexOf(sp) != -1) {
		str = data.split(sp)[0]
	} else {
		str = data
	}
	return str
}


export default util;
